//
//  DataTool.m
//  get30Before
//
//  Created by liuzhishan on 15/12/16.
//  Copyright © 2015年 shanshan. All rights reserved.
//

#import "DataTool.h"

@implementation DataTool


+(NSString *)getDateWithMS:(long long )time
{
    NSDate *date = [[NSDate alloc]initWithTimeIntervalSince1970:time/1000.0];
    
    return  [self getStrWithDate:date];
    
    
}
+(NSDate *)getDate:(NSDate*)date Before:(NSInteger)beforeCount
{
    NSTimeInterval time =   beforeCount * 24 * 60 * 60;
    
    NSDate * lastMonth = [date dateByAddingTimeInterval:-time];
    
    
    return  lastMonth;

}
+(NSDate *)getDateBefore:(NSInteger)beforeCount
{
    NSDate * date = [NSDate date];
  
    NSTimeInterval time =   beforeCount * 24 * 60 * 60;
    
    NSDate * lastMonth = [date dateByAddingTimeInterval:-time];
    
    
    return  lastMonth;
}


+(NSString*)getStrWithDate:(NSDate *)date
{
    
    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    //转化为字符串
    NSString * startDate = [dateFormatter stringFromDate:date];
    
    return startDate;


    
}
+(NSString *)removeDateYear:(NSString *)date
{
    NSArray *array = [date componentsSeparatedByString:@"-"];
    NSString *str = [array firstObject];
    str = [NSString stringWithFormat:@"%@%@",str,@"-"];
    
   return [date stringByReplacingOccurrencesOfString:str withString:@""];
 
    
}



/*
  两种情况
  1。后边时期 大于前边日期  两个月   变成 前边日期 ＋ 30  ＝ 后边日期
  2。后边日期 小于前边 日期         变成 前边日期 ＋ 30  ＝ 后边日期
 */
+(BOOL)firstDate:(NSDate *)firstDate andSecondDate:(NSDate *)lastDate andCompareInterval:(NSInteger)intervalNub
{
    
    //nslog(@"%@",[DataTool getStrWithDate:lastDate]);
    //nslog(@"%@",[DataTool getStrWithDate:firstDate]);
    
    
   NSTimeInterval timeInterval =  [lastDate timeIntervalSinceDate:firstDate];

    
    if([[DataTool getStrWithDate:lastDate] compare:[DataTool getStrWithDate:firstDate]] == NSOrderedAscending)
    {
        return YES;
    }
    
    timeInterval = timeInterval / (24*60*60.0);
    
    //nslog(@"4444444444%lf",timeInterval);
    
    if (timeInterval > intervalNub) {
        
        return YES;
    }
    
    return NO;
}


@end
